package com.rawm.gen.utils.generate;


import com.rawm.gen.common.Constant;
import com.rawm.gen.entity.Mapper;
import com.rawm.gen.support.IGenerate;
import com.rawm.gen.utils.common.StrUtils;
import com.rawm.gen.utils.freemarker.FreeMarkerTemplateUtils;

import java.io.File;

/**
 * @author 啃过雪糕的兔子
 * @to TODO
 * @date 2018年7月1日 下午1:59:40
 * @see:<p>www.aixuegao.cn</p>
 * @since 1.0.1
 */
public class GenerateMapper implements IGenerate<Mapper> {

    @Override
    public void generateFile(Mapper mapper) throws Exception {
        final String path = StrUtils.getAbsolutePath()
                + Constant.SRC_PATH
                + StrUtils.package2path(mapper.getPackageName()
                + Constant.DOT);
        final String templateName = "Mapper.ftl";
        File pat = new File(path);
        if (!pat.exists()) {
            pat.mkdirs();
        }
        String filePath = path + mapper.getEntityName() + "Mapper" + Constant.MAPPINGS_SUFFIX;
        File file = new File(filePath);
        FreeMarkerTemplateUtils.generateFile(templateName, file, mapper);
        System.out.println("Generate Mapper");
    }
}
